<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2019-11-08
 * Time: 14:21
 */

namespace app\api\controller\v1;

use app\api\controller\BaseController;
use app\api\service\AdminWxRefund;
use app\api\service\Pay as PayService;
use app\api\service\WxNotify;
use app\api\service\WxRefund;
use think\facade\Request;

require './../extend/WxPay/WxPay.Api.php';

class Pay extends BaseController
{
    protected $beforeActionList = [
        'checkExclusiveScope' => ['only' => 'getPreOrder']
    ];

    // 获取支付信息
    public function getPreOrder($out_trade_no)
    {
        $pay = new PayService($out_trade_no);
        return $pay->pay();
    }

    public function receiveNotify()
    {
        /**
         * 通知频率15/15/30/180/1800/1800/1800/1800/3600 单位:秒
         * 1.检测库存量，超卖
         * 2.更新这个订单的status状态
         * 3.减库存
         * 如果成功处理，我们返回微信成功处理的消息。否则，我们需要返回没有成功处理
         * 特点: post xml格式  不会携带参数
         */
        $notify = new WxNotify();
        $config = new \WxPayConfig();
        $notify->Handle($config,true);

    }

    /**
     * 退款操作
     */
    public function orderRefund($order_id)
    {
        $refund = new WxRefund($order_id);
        return $refund->entrance();
    }


    /**
     * 后台退款操作
     */
    public function adminOrderRefund()
    {
        $post = Request::post();
        $adminWxRefend = new AdminWxRefund($post);
        return $adminWxRefend->entrance();
    }
}